package com.example.data.factory.web1.controller;

import com.example.data.factory.common.Dto.*;
import com.example.data.factory.common.result.R;
import com.example.data.factory.entity.entity.DatabaseInfo;
import com.example.data.factory.service.service.DatabaseInfoService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.sql.SQLException;

/**
 * <p>
 * 数据库信息 前端控制器
 * </p>
 *
 * @author lhy
 * @since 2025-03-03
 */
@RestController
@RequestMapping("/databaseInfo")
public class DatabaseInfoController {
    @Resource
    private DatabaseInfoService databaseInfoService;

    @GetMapping("/SerachDataBase")
    public R<DatabaseInfo> SearchDataBase(SerachDataBaseDto serachDataBaseDtoc) {
        return databaseInfoService.search ( serachDataBaseDtoc );
    }

    @PostMapping("/InsertDataBase")
    public R<DatabaseInfo> InsertDataBase(@RequestBody @Validated InsertDataBaseDto insertDataBaseDto, HttpServletRequest request) {
        return databaseInfoService.insert ( insertDataBaseDto, request );
    }

    @PutMapping("/UpdateDataBase")
    public R<DatabaseInfo> UpdateDataBase(@RequestBody @Validated UpdateDataBaseDto updateDataBaseDto) {
        return databaseInfoService.updates ( updateDataBaseDto );
    }

    @PutMapping("/UpdateDataBaseStatus")
    public R<DatabaseInfo> UpdateDataBaseStatus(@RequestBody UpdateDataBaseStatus updateDataBaseStatus) {
        return databaseInfoService.updatestatus ( updateDataBaseStatus );
    }

    @DeleteMapping("/DeleteDataBase")
    public R<DatabaseInfo> DeletDataBase(@RequestBody DeleteDataBaseDto deleteDataBaseDto) {
        return databaseInfoService.deletes ( deleteDataBaseDto );
    }

    @GetMapping("/database-connection/test-all")
    public R<?> testAllConnection(DataBaseConnectDto dataBaseConnectDto) throws SQLException {
        return databaseInfoService.testDatabaseConnection ( dataBaseConnectDto );
    }
}
